<?php
/**
 * @version      BOSSCMS-Free
 * @trademark    BOSSCMS
 * @copyright    Copyright © by BOSSCMS-Free (https://www.bosscms.net/) 保留所有权利
 * @license      https://gitee.com/Greenpeas/BOSSCMS/license/ 和 https://www.bosscms.net/freelicense/
 * @link         https://www.bosscms.net/
 * @author       温州软界网络技术有限公司
**/
defined('IS_OK') or exit('Access Forbidden');

into::basic_class('admin');

class iframe extends admin
{	
    public function navs()
    {
		global $G;
		$ismob = isMobile();
		into::basic_json('navadm',true);
		$nav = $G['navadm'];
		unset($G['navadm']);
		$plugin = arrOptions(page::plugin_list('*'),'name');
		$sort = array();
		foreach($nav as $key=>$val){
			foreach($val['child'] as $k=>$v){
				if($G['manager']['level']!=1){
					if($v['child']){
						foreach($v['child'] as $l=>$w){
							if(!$this->cover($this->build($w),'R',true)){
								if($ns = into::load_class('admin','manager','manager','new')->isnav($w['mold'],$w['part'])){
									$u = array_shift($ns);
									foreach(array('mold','part','func','param') as $p){
										$nav[$key]['child'][$k]['child'][$l][$p] = $u[$p];
									}
								}else{
									unset($nav[$key]['child'][$k]['child'][$l]);
								}
							}
						}
					}
				}
				if($arr = $nav[$key]['child'][$k]['child']){
					foreach($arr as $l=>$w){
						if($w['mold']=='plugin'){
							$tags = array($w['tag']);
							foreach($plugin as $k2=>$v2){
								if(!$v2['must']){
									$tags[] = (is_file(ROOT_PATH.'system/plugin/'.$k2.'/navadm.json')?'plugin_':'').$k2;
								}
							}
							$nav[$key]['child'][$k]['child'][$l]['tag'] = implode(' ',$tags);
						}
						if($pg = $plugin[$w['mold']]){
							$nav[$key]['plugin'] = $w['mold'].' '.($pg['must']?'':'hide');
						}
					}
				}
				if(!$nav[$key]['child'][$k]['child'] && !strstr($nav[$key]['icon'],'plugin')){
					unset($nav[$key]['child'][$k]);
				}
			}
			if(!$nav[$key]['child']){
				unset($nav[$key]);
			}
			$sort[$key] = isset($val['sort'])?$val['sort']:99;
		}
		asort($sort);
		$navs = array();
		foreach($sort as $k=>$v){
			$navs[$k] = $nav[$k];
		}
		unset($nav);
        return $navs;
    }
	
	public function init()
	{
		global $G;
		$G['no_copyright'] = true;
		$G['plugin_must'] = array();	
		$plugin_must = page::plugin_list('*','must=1','id DESC');	
		foreach($plugin_must as $k=>$v){
			if(!is_file(ROOT_PATH.'system/plugin/'.$v['name'].'/navadm.json')){
				$config = load::plugin($v['name']);
				$G['plugin_must'][$k] = array(
					'title' => $config['title'],
					'mold' => $v['name'],
					'check' => $config['check']?$config['check']:'R'
				);
				if(!$this->cover($v['name'],'R',true)){
					if($ns = into::load_class('admin','manager','manager','new')->isnav($v['name'],$v['name'])){
						$u = array_shift($ns);
						foreach(array('mold','part','func','param') as $p){
							$G['plugin_must'][$k][$p] = $u[$p];
						}
					}else{
						unset($G['plugin_must'][$k]);
					}
				}
			}
		}	
		$data = array();
        $data['language'] = page::language_list();
		$data['navs'] = self::navs();
		echo $this->theme('iframe/iframe', $data);
	}
}
?>